﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.SynonymKeywords.Service
{
    public class AgentAssistSynonymKeywordAppService : BaseAppService, ISynonymKeywordAppService
    {
        private ISynonymKeywordDomainService _domainService;

        public AgentAssistSynonymKeywordAppService(ISynonymKeywordDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SYNONYMKEYWORD, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SYNONYMKEYWORD, AuditAction.CREATE)]
        public SynonymKeywordDto Add(SynonymKeywordCreateDto dto)
        {
            var obj = Mapper.Map<SynonymKeyword>(dto);
            obj.Id = Guid.NewGuid();
            SynonymKeyword synonymKeyword = _domainService.Create(obj);
            return Mapper.Map<SynonymKeywordDto>(synonymKeyword);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SYNONYMKEYWORD, AuditAction.UPDATE)]
        public SynonymKeywordDto Update(Guid id, SynonymKeywordUpdateDto dto)
        {
            var obj = Mapper.Map<SynonymKeywordUpdateBo>(dto);
            obj.Id = id;
            SynonymKeyword synonymKeyword = _domainService.Update(obj);
            return Mapper.Map<SynonymKeywordDto>(synonymKeyword);
        }

        public SynonymKeywordDto Get(Guid id)
        {
            SynonymKeyword synonymKeyword = _domainService.Get(id);
            return Mapper.Map<SynonymKeywordDto>(synonymKeyword);
        }

        public IEnumerable<SynonymKeywordDto> List()
        {
            IEnumerable<SynonymKeyword> list = _domainService.List();
            return Mapper.Map<IEnumerable<SynonymKeywordDto>>(list);
        }
    }
}
